## Instructions for replicating Ratkovic and Tingley 2023.
# Two sets of results are presented in the paper.
# For the first, we do a single set of illustrative simulations and reanalyze and earlier
# study.  This was done on a Macbook Pro running Catalina and can be done
# locally.  These analyses are in (1)-(4) below.
# For the second, we ran two sets of simulation on a high performance cluster.  Replicating
# the simulation results should be done in this setting, as running it locally is 
# time prohibitive. We have included the script that runs a _single_ simulation across 
# all settings below in (5)-(6).

# 1) MDEI
# Install MDEI_JOP.tar.gz to recover the version of MDEI used in this manuscript.
# 2) Specific packages used for simulations
devtools::install_github("lukesonnet/KRLS",ref="614c8d78797ed495c597cee0a9a17b07275f3387")
devtools::install_github("grf-labs/grf", subdir = "r-package/grf", ref="73ddbf75268333a650fbee8898162023728d6b04")
install_version("RcppArmadillo", version = "0.9.900.3.0",repos = "http://cran.us.r-project.org")
# 3) Additional, stable packages used in the replication files
library(xtable)
library(tictoc)
library(foreign)
library(gam)
library(splines2)
library(gridExtra)
library(MASS)
# 4) Replicating the results in the paper, with files named
# by their appearance in the manuscript
# Spline bases used by MDEI
source('Figure1_basesExample.R')
# Illustrative example quadratic in treatment effect
source('Figures2and3_quadraticTreatmentModel.R')
# Large-sample simulation with misspecification
source('Figure5_50kfigure.R')
# Bechtel and Hainmueller replication
source('Table1_Figure6_Figure7_BHReplication.R')

# 5) Additional files used in simulations.
  # The full set of simulations were run on a server.  These scripts generate
  # a single simulation.
# The simulation file for the split sample/conformal simulations in Sec 3.2.
source('IllustrativeSimsSec3.2_Body.R')
# Performance simulations in the Appendix.
source('PerformanceSims_Appendix.R')